function back() {
  location.href = '/books'
}

function bookAdd() {
  let dataAll = document.querySelectorAll('input[name]')
  let [i1, i2, i3, i4] = dataAll
  let bookName = i1.value
  let author = i2.value
  let publishedAt = i3.value
  let descriptions = i4.value
  let obj = {
    bookName,
    author,
    publishedAt,
    descriptions
  }

  let arrString = window.location.href.split('/');
  let id = arrString[arrString.length - 1] * 1;
  if (id > 0) {
    axios.put(`/books/${id}`, obj).then(res => {
      if (res.status === 200) {
        alert('修改成功')
      }
    })
  } else {
    axios.post('/books', obj).then(res => {
      if (res.status === 200) {
        alert('添加成功')

      }
    })
  }
  location.href = '/books'
}